package com.kl.controller;


import com.kl.em.ConstantEnum;
import com.kl.em.Result;
import com.kl.entity.Coupon;
import com.kl.entity.SeckillCoupon;
import com.kl.service.ICouponService;
import com.kl.service.ISeckillCouponService;
import com.kl.service.IUserCouponService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("seckillCouponController")
public class SeckillCouponController {
/*
    @Autowired
    private ISeckillCouponService seckillCouponService;
    @Autowired
    private IUserCouponService userCouponService;
    @Autowired
    private ICouponService couponService;

    //秒杀优惠券信息查询接口
    @ApiOperation(value = "秒杀优惠券信息查询接口")
    @GetMapping// @ResponseBody  将后台的数据以json的格式返回前台
    public Result selectAll(){// @RequestBody  将前端传入的json格式的数据绑定到实体类
        List<SeckillCoupon> seckillCouponList = seckillCouponService.seselectAll();
        return Result.build(ConstantEnum.SUCCESS).setResult(seckillCouponList);
    }

    //秒杀优惠券信息抢购接口
    @ApiOperation(value = "秒杀优惠券信息抢购接口")
    @ApiImplicitParams({
            //name为方法中的参数名，value就是它的含义，required 是否必填
            @ApiImplicitParam(name = "userId",value = "用户Id",required = true,paramType = "query"),
            @ApiImplicitParam(name = "seckillCouponId",value = "秒杀优惠卷Id",required = true,paramType = "query")
    })
    @PostMapping// @ResponseBody  将后台的数据以json的格式返回前台
    public Result selectById(@RequestParam("userId") String userId,@RequestParam("seckillCouponId")Long seckillCouponId){// @RequestBody  将前端传入的json格式的数据绑定到实体类
        List<Coupon> contactsList = null;
        try {
            //获取秒杀优惠券
            SeckillCoupon seckillCoupon = seckillCouponService.getById(seckillCouponId);
            Coupon coupon = new Coupon();
            coupon.setCouponType(seckillCoupon.getCouponType());
            coupon.setStartTime(new Date());

            Calendar calendar = Calendar.getInstance(); //Calendar类   日期的加减
            calendar.add(Calendar.DATE,Integer.valueOf(seckillCoupon.getEffectiveTime()).intValue());
            coupon.setEndTime(calendar.getTime());

            coupon.setCrateTime(new Date());
            coupon.setCouponSum(seckillCoupon.getCouponSum());



        }catch (Exception e){
            e.printStackTrace();
            return Result.build(ConstantEnum.ERROR);
        }
        return Result.build(ConstantEnum.SUCCESS).setResult(contactsList);
    }*/
}
